package com.hyt.it.ogt.kq.service.bm.feign.tps;

import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.common.utils.exception.RemoteRequestExcepton;
import com.hyt.common.utils.result.Result;
import com.hyt.core.exception.NestedBusinessException;
import com.hyt.it.ogt.kq.service.bm.feign.tps.model.WeChatMiniAppConfig;
import com.hyt.it.ogt.kq.service.bm.feign.tps.model.WxMiniAppSubscribeMsg;
import com.hyt.it.ogt.kq.service.bm.feign.tps.model.WxOffiaccountTemplateMsg;
import com.hyt.it.ogt.kq.service.bm.model.vo.CallBackParam;
import com.hyt.it.ogt.kq.service.bm.model.vo.InvoiceSaveVo;
import com.hyt.model.tps.entity.InvoiceBase;
import com.hyt.model.tps.entity.PeePayNotify;
import com.hyt.model.tps.vo.*;

import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * feign客户端熔断器
 */
@Component
@Slf4j
public class TpsClientHystrix implements FallbackFactory<TpsClient> {


    @Override
    public TpsClient create(Throwable throwable) {
		log.error("# TpsClient Hystrix message ", throwable);

        return new TpsClient() {
            @Override
            public Object pay(PayRequestVo payBase) throws Exception {
                log.error("#支付失败，进入熔断");
                throw new Exception("支付失败");
            }

            @Override
            public Object payWechat(PayRequestVo payBase) throws Exception {
                log.error("#支付失败，进入熔断");
                throw new Exception("支付失败");
            }

            @Override
            public Object payQuery(PayQueryVo queryVo) throws Exception {
                log.error("#支付查询考失败，进入熔断");
                throw new Exception("支付查询考失败");
            }

            @Override
            public Object refund(RefundVo queryVo) throws Exception {
                log.error("#退款失败，进入熔断");
                throw new Exception("退款失败");
            }
            
            @Override
            public String getPayProvider(String officeId) throws Exception {
                log.error("#查询支付供应商失败，进入熔断");
                throw new Exception("查询支付供应商失败");
            }

            @Override
            public Object getQRCode(@RequestParam String officeId, @RequestParam String scene, @RequestParam String page, @RequestParam Integer width) throws Exception {
                log.error("#获取二维码失败，进入熔断");
                throw new Exception("获取二维码失败");
            }

            @Override
            public Object getBmQRCode(@RequestParam String officeId, @RequestParam String scene, @RequestParam String page, @RequestParam Integer width) throws Exception {
                log.error("#获取二维码失败，进入熔断");
                throw new Exception("获取二维码失败");
            }

            @Override
            public Object getBmQRCodeHwCloud(@RequestParam String officeId, @RequestParam String scene, @RequestParam String page, @RequestParam Integer width) throws Exception {
                log.error("#获取二维码失败，进入熔断");
                throw new Exception("获取二维码失败");
            }

            @Override
            public ApiResponse<Object> pushWxMiniAppSubscribeMessage(@RequestBody List<WxMiniAppSubscribeMsg> wxMiniAppSubscribeMsgs) {
                log.error("# 推送微信小程序订阅消息失败，进入熔断");
                throw new RemoteRequestExcepton("推送微信小程序订阅消息失败");
            }

            @Override
            public ApiResponse<Object> pushWeChatOffiAccountTemplateMessage(List<WxOffiaccountTemplateMsg> wxOffiaccountTemplateMsgs) {
                log.error("# 推送微信公众号模板消息失败，进入熔断");
                throw new RemoteRequestExcepton("推送微信公众号模板消息失败");
            }

            @Override
            public Object analysis(Analysis analysis) throws Exception {
                log.error("#解析失败，进入熔断");
                throw new Exception("解析失败");
            }

            @Override
            public InvoiceBase queryInvoiceBase(String officeId) throws Exception {
                log.error("#解析失败，进入熔断");
                throw new Exception("解析失败");
            }

            @Override
            public String invoiceInterface(InvoiceSaveVo vo) throws Exception {
                throw new Exception("调用失败");
            }

            @Override
            public String syncInvoiceResult(CallBackParam param) throws Exception {
                throw new Exception("调用失败");
            }

            @Override
            public String syncInvoiceResultV2(CallBackParam param) throws Exception {
                throw new Exception("调用失败");
            }

            @Override
            public String getBucketTempCredential(String officeId) throws Exception {
                log.error("#查询失败，进入熔断");
                throw new Exception("查询失败");
            }

            @Override
            public boolean peePayHmac(PeePayNotify peePayNotify) throws Exception {
                log.error("#调用失败，进入熔断");
                throw new Exception("调用失败");
            }

            @Override
            public WeChatMiniAppConfig getWxConfig(String officeId, String supplierType) {
                log.error("#调用获取报名微信小程序的配置，进入熔断");
                throw new RemoteRequestExcepton("获取报名微信小程序的配置失败");
            }

            @Override
            public Result uploadFileToHuawei(String officeId, String path, byte[] bytes) {
                log.error("#调用失败，进入熔断");
                throw new RemoteRequestExcepton("调用失败");
            }
            @Override
            public String getBucketTempCredential() {
                log.error("#调用失败，进入熔断");
                throw new RemoteRequestExcepton("调用失败");
            }

			@Override
			public String sendMessage(MessageVo messageVo) {
				 log.error("#发送短信失败，进入熔断");
			     throw new RemoteRequestExcepton("发送短信失败");
			}

			@Override
			public String analysisYopNotifyStr(String analysisYopNotifyStr, String officeId) throws Exception {
				log.error("#解析易宝支付回调数据失败，进入熔断");
			    throw new RemoteRequestExcepton("解析易宝支付回调数据失败");
			}

            @Override
            public String getNcNonTaxPayPrivateKey(String officeId) {
                log.error("#获取南昌非税系统私钥，进入熔断");
                throw new RemoteRequestExcepton("获取南昌非税系统私钥失败");
            }
            
            @Override
            public ApiResponse<String> uploadFileToTencent(String officeId, @RequestParam String path, @RequestBody byte[] bytes) {
                log.error("#上传图片到存储桶失败，进入熔断");
                throw new NestedBusinessException("上传图片到存储桶失败");
            }
        };
    }
}
